<template>
<div>
  <form class="form-inline">
    <div class="form-group">
      <label for="c_plan_year">年份：</label>
      <v-select id="c_plan_year" :value.sync="c_plan_year"
      :options='c_year_list' close-on-select clear-button></v-select>
      <button type="button" class="btn btn-success width-80" @click="search()">查询</button>
    </div>
  </form>
  <table class="table table-bordered">
    <thead class="thead-default">
      <th>分公司</th>
      <th>年</th>
      <th>计划</th>
      <th>已检</th>
      <th>入户</th>
      <th>拒检</th>
      <th>到访不遇</th>
      <th>应修</th>
      <th>已修</th>
      <th>A类隐患</th>
      <th>B类隐患</th>
      <th>C类隐患</th>
    </thead>
    <tr v-for="row in model.rows">
        <td @click="gotoDetail(row)">{{row.f_subcompany}}<span class="glyphicon glyphicon-option-horizontal"></span></td>
        <td>{{row.f_plan_year}}</td>
        <td>{{row.cplan}}</td>
        <td>{{row.call}}</td>
        <td>{{row.centry}}</td>
        <td>{{row.cdeny}}</td>
        <td>{{row.cabsent}}</td>
        <td>{{row.ctoberepaired}}</td>
        <td>{{row.crepaired}}</td>
        <td>{{row.clevel1}}</td>
        <td>{{row.clevel2}}</td>
        <td>{{row.clevel3}}</td>
    </tr>
  </table>
  <div style="height:50px;"></div>
</div>
</template>


<script>
import co from 'co'
import Vue from 'vue'

let search = function * (self) {
  let splash = yield self.$post('rs/sql/汇总查询', {data: {f_plan_year: self.c_plan_year[0], f_subcompany: self.f_subcompany}}, {resolveMsg: null, rejectMsg: '查询出错！'})
  self.$set('model.rows', splash.data)
}

export default {
  title: '安检概况',
  props: ['f'],
  data() {
    let options = []
    let year = (new Date()).getFullYear()
    for(let i = year - 8; i <= year +1; i++ )
      options.push({label: i+'', value: i+''})
    return {
      c_plan_year: year + '',
      c_year_list: options,
      model: {
        rows: []
      }
    }
  },
  methods: {
    search () {
      let gen = search(this)
      return co(gen)
    },
    gotoDetail (row) {
      this.$goto('splash-detail', {f_plan_year: row.f_plan_year, f_subcompany: row.f_subcompany}, 'self')
    }
  },
  ready () {
    this.f_subcompany = Vue.f_subcompany
    this.search()
  }
}
</script>
